﻿namespace BinarySearchTree
{
    class TreeNode<T>
    {
        private TreeNode<T> left;
        private TreeNode<T> right;
        private TreeNode<T> parent;
        private T data;
        private bool addLeft = true;

        public TreeNode<T> Left
        {
            get
            {
                return left;
            }
            set
            {
                left = value;
            }
        }

        public TreeNode<T> Right
        {
            get
            {
                return right;
            }
            set
            {
                right = value;
            }
        }

        public TreeNode<T> Parent
        {
            get
            {
                return parent;
            }
            set
            {
                parent = value;
            }
        }

        public T Data
        {
            get
            {
                return data;
            }
            set
            {
                data = value;
            }
        }

        public TreeNode()
        {
            Left = null;
            Right = null;
            Parent = null;
        }

        public void Add(TreeNode<T> node)
        {
            if (this.Left == null)
            {
                this.Left = node;
            }
            else if (this.Right == null)
            {
                this.Right = node;
            }
            else if (addLeft)
            {
                this.Left.Add(node);
            }
            else
            {
                this.Right.Add(node);
            }
        }
    }
}